package com.net.xpay.web.controller.merchant;

import com.net.xpay.web.vo.NotificationVo;
import com.net.common.model.ResultData;
import com.net.xpay.common.domain.User;
import com.net.xpay.common.domain.notification.Notification;
import com.net.xpay.common.model.FetchNotificationModel;
import com.net.xpay.common.service.notification.NotificationService;
import com.net.xpay.core.utils.BeanCopierUtil;
import com.net.xpay.web.secutiry.RequestUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

@Slf4j
@RestController
@RequestMapping("/merchant/notification")
@Api(tags = "商家/系统公告", description = "商家 系统公告 net")
public class NotificationController {

    @Autowired
    private NotificationService notificationService;

    @ApiOperation(value = "查询模块的未读公告")
    @PostMapping("/fetch-unread-by-module")
    public ResultData<NotificationVo> fetchUnreadNotificationByModule(@ApiIgnore @RequestUser User merchant, @RequestBody FetchNotificationModel fetchModel) {
        Notification notification = notificationService.fetchOneByModule(merchant.getId(), fetchModel);
        if (notification == null) {
            return new ResultData<>();
        }
        NotificationVo notificationVo = new NotificationVo();
        BeanCopierUtil.copy(notification, notificationVo);
        return new ResultData<>(notificationVo);
    }
}
